﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace XNAREUSABLES
{
    /// <summary>
    /// A shader pool for grabbing loaded shaders from anywhere in the program.
    /// </summary>
    public static class ShaderPool
    {
        /// <summary>
        /// The pool object
        /// </summary>
        private static Dictionary<string, Effect> Pool = new Dictionary<string, Effect>();

        /// <summary>
        /// A reference to the content manager to load shaders on the fly.
        /// </summary>
        private static ContentManager Content;

        /// <summary>
        /// Called once at the start of application to initialize all members.
        /// </summary>
        /// <param name="Content"></param>
        public static void INIT(ContentManager Content)
        {
            // Associate content manager.
            ShaderPool.Content = Content;
        }

        /// <summary>
        /// Used to load a shader into the shader pool
        /// </summary>
        /// <param name="Index_Name">The desired name for referencing this shader from the pool.</param>
        /// <param name="Load_Path">The path of the shader to be loaded with the content manager.</param>
        public static void LOAD_SHADER(string Index_Name, string Load_Path)
        {
            // Load shader and put it into dictionary.
            Pool.Add(Index_Name, Content.Load<Effect>(Load_Path));
        }

        /// <summary>
        /// Grab a desired shader from the pool by name.
        /// </summary>
        /// <param name="Index_Name">The reference name of the shader to be pulled from the pool.</param>
        /// <returns>Shader from pool.</returns>
        public static Effect Get(string Index_Name)
        {
            return Pool[Index_Name];
        }

        /// <summary>
        /// Grab a desired shader from the pool by index.
        /// </summary>
        /// <param name="Index"></param>
        /// <returns></returns>
        public static Effect Get(int Index)
        {
            return Pool.ElementAt(Index).Value;
        }
    }
}
